package com.incar.chuxing.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * Created by Michael Pi on 2016/10/18.
 */
public class VerControlUtils {

    private Context mContext;
    public static VerControlUtils instance;

    public VerControlUtils(Context mContext) {
        this.mContext = mContext;
    }


    public static VerControlUtils getInstance(Context context) {
        if (instance == null && context != null) {
            instance = new VerControlUtils(context);
        }
        return instance;
    }

    public String getVersionName() {
        try {
            PackageManager packageManager = mContext.getPackageManager();
            PackageInfo packInfo = packageManager.getPackageInfo(mContext.getPackageName(), 0);
            return packInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return "";
    }

    public int getVersionCode() {
        try {
            PackageManager packageManager = mContext.getPackageManager();
            PackageInfo packInfo = packageManager.getPackageInfo(mContext.getPackageName(), 0);
            return packInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return 0;
    }


}

